package utils
{
	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.display.DisplayObject;
	import flash.events.TimerEvent;
	import flash.events.Event;
	
	public class BlinkObject
	{
		
		private var _object:DisplayObject;
		private var _times:int;
		private var _totalTime:Number;
		private var _myTimer:Timer;
		
		public function BlinkObject()
		{
			_times=10;
			_totalTime=5000;
			_myTimer = new Timer(_totalTime/_times, _times);
			_myTimer.addEventListener(TimerEvent.TIMER, onBlink);
			_myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, finishBlink);

		}
		
		public function startBlinkObject(obj:DisplayObject, times:int, totaltime:Number):void {
			_object=obj;
			_times=times;
			_totalTime=totaltime;
			_myTimer.delay=_totalTime/_times;
			_myTimer.repeatCount=_times;
			
			startTimer();
		}
		
		private function startTimer():void {
			_myTimer.start();
		}
		
		private function finishBlink(event:TimerEvent):void {
			_object.visible=true;
			_myTimer.stop();
			_myTimer.reset();
		}
		
		private function onBlink(event:TimerEvent):void {
			if (_object.visible){
				_object.visible=false;
			}else{
				_object.visible=true;
			}
		}
	}
}